<?php

class Application_Model_AclGroup extends Sgit_Model
{  
    protected $_name = 'acl_groups';
    protected $_primary = 'id';
    protected $_cache_activa = TRUE;



    function getGrupoByIdUser($id){
        
        $db=$this->getAdapter();
        
        $select = $db->select()->from(array($this->_name),array('grupo') );
        $select->where("id_user = ?", $id, 'INTEGER');
        $select->order("grupo");
        $select->joinLeft(array('acl_user_groups'),
                    'acl_user_groups.id_group = acl_groups.id',
                    array() ); 
        
        $col = $db->fetchCol($select);

        return $col;
    }
    
    function getIdGrupoByIdUser($id){
        
        $db=$this->getAdapter();
        
        $select = $db->select()->from(array($this->_name),array('id') );
        $select->where("id_user = ?", $id, 'INTEGER');
        $select->order("id");
        $select->joinLeft(array('acl_user_groups'),
                    'acl_user_groups.id_group = acl_groups.id',
                    array() ); 
        
        $col = $db->fetchCol($select);

        return $col;
    }
    
    
    function getGruposPerUser(){
        
        $db=$this->getAdapter();
        
        $select = $db->select()->from(array($this->_name),array('grupo') );
    
        $select->order(array("id_user","grupo ASC"));
        $select->joinLeft(array('acl_user_groups'),
                    'acl_user_groups.id_group = acl_groups.id',
                    array('id_user') ); 
        
        $rows = $db->fetchAll($select);
        
        $col=$this->assocArray($rows,'id_user','grupo');
        
        return $col;
    }


}


    

